﻿/************************************************************************************
* Copyright (c) 2019 All Rights Reserved.
*命名空间：Merge.BLL
*文件名： Parameter
*创建人： Liebeskind
*创建时间：2019/6/24 17:25:10
*描述
*=====================================================================
*修改标记
*修改时间：2019/6/24 17:25:10
*修改人：Liebeskind
*描述：
************************************************************************************/
using Commonality.DAL.MySQL;
using Commonality.Model.Tray;
using Commonality.Model.Xml;
using Merge.Model;
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace Merge.BLL
{
    public class Parameter
    {
        public static string parameterFeilName = Application.StartupPath + @"\Parameter\Parameter.xml";
        #region 数据库
        public static void MySQLParameterLoad()
        {
            try
            {
                MySqlFunction.InitMySQLFunction();
                MySQLParameter.Host = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "MySQL", "Host");
                MySQLParameter.Password = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "MySQL", "Password");
                MySQLParameter.UserID = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "MySQL", "UserID");
                MySqlFunction.MySql.DataSource = MySQLParameter.Host;
                MySqlFunction.MySql.Password = MySQLParameter.Password;
                MySqlFunction.MySql.UserId = MySQLParameter.UserID;
            }
            catch (Exception)
            {
            }
        }
        public static void UpdateMySQLHost(string host)
        {
            XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "MySQL", "Host", host);
            MySqlFunction.MySql.DataSource = host;
        }
        public static void UpdateMySQLPassword(string password)
        {
            XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "MySQL", "Password", password);
            MySqlFunction.MySql.Password = password;
        }
        public static void UpdateMySQLUserId(string userId)
        {
            XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "MySQL", "UserID", userId);
            MySqlFunction.MySql.UserId = userId;
        }
        #endregion
        #region Model类型集合元素
        public static void TrayModelElementLoad()
        {
            try
            {
                string[] modelX01 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X01").Split(new char[] { '|' });
                string[] modelX03 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X03").Split(new char[] { '|' });
                string[] modelX05 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X05").Split(new char[] { '|' });
                string[] modelX08 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X08").Split(new char[] { '|' });
                string[] modelX13 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X13").Split(new char[] { '|' });
                string[] modelX15 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X15").Split(new char[] { '|' });
                string[] modelX176 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X176").Split(new char[] { '|' });
                string[] modelX177 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X177").Split(new char[] { '|' });
                string[] modelX178 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X178").Split(new char[] { '|' });
                string[] modelX19 = XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayModelSets", "X19").Split(new char[] { '|' });
                foreach (string item in modelX01)
                {
                    if (item != "" && item != null)
                    {
                        Tray.X01.Add(item);
                    }
                }
                foreach (string item in modelX03)
                {
                    if (item != "" && item != null)
                    {
                        Tray.X03.Add(item);
                    }
                }
                foreach (string item in modelX05)
                {
                    if (item != "" && item != null)
                    {
                        Tray.X05.Add(item);
                    }
                }
                foreach (string item in modelX08)
                {
                    if (item != "" && item != null)
                    {
                        Tray.X08.Add(item);
                    }
                }
                foreach (string item in modelX13)
                {
                    if (item != "" && item != null)
                    {
                        Tray.X13.Add(item);
                    }
                }
                foreach (string item in modelX15)
                {
                    if (item != "" && item != null)
                    {
                        Tray.X15.Add(item);
                    }
                }
                foreach (var item in modelX176)
                {
                    if (item != "" && item != null) Tray.X176.Add(item);
                }
                foreach (var item in modelX177)
                {
                    if (item != "" && item != null) Tray.X177.Add(item);
                }
                foreach (var item in modelX178)
                {
                    if (item != "" && item != null) Tray.X178.Add(item);
                }
                foreach (var item in modelX19)
                {
                    if (item != "" && item != null) Tray.X19.Add(item);
                }
            }
            catch (Exception)
            {
            }
        }
        public static void UpdateTrayModelElement(TrayModel model, List<string> modelSets)
        {
            string Sets = "";
            foreach (string item in modelSets)
            {
                Sets += item + "|";
            }
            switch (model)
            {
                case TrayModel.NULL:
                    break;
                case TrayModel.X01:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X01", Sets);
                    break;
                case TrayModel.X03:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X03", Sets);
                    break;
                case TrayModel.X05:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X05", Sets);
                    break;
                case TrayModel.X08:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X08", Sets);
                    break;
                case TrayModel.X13:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X13", Sets);
                    break;
                case TrayModel.X15:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X15", Sets);
                    break;
                case TrayModel.X176:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X176", Sets);
                    break;
                case TrayModel.X177:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X177", Sets);
                    break;
                case TrayModel.X178:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X178", Sets);
                    break;
                case TrayModel.X19:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayModelSets", "X19", Sets);
                    break;
                default:
                    break;
            }
        }
        #endregion

        #region Tray型号位映射参数
        /// <summary>
        /// 加载Tray仓位映射参数
        /// </summary>
        public static void TrayGatherParameterLoad()
        {
            try
            {
                TrayMap.X01 = (Seat)Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayMap", "X01"));
                TrayMap.X03 = (Seat)Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayMap", "X03"));
                TrayMap.X05 = (Seat)Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayMap", "X05"));
                TrayMap.X08 = (Seat)Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayMap", "X08"));
                TrayMap.X13 = (Seat)Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayMap", "X13"));
                TrayMap.X15 = (Seat)Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayMap", "X15"));
                TrayMap.X176 = (Seat)Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayMap", "X176"));
                TrayMap.X177 = (Seat)Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayMap", "X177"));
                TrayMap.X178 = (Seat)Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayMap", "X178"));
                TrayMap.X19 = (Seat)Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayMap", "X19"));
            }
            catch (Exception)
            {
            }

        }
        /// <summary>
        /// 空Tray参数映射设置
        /// </summary>
        /// <param name="storehouse">映射仓位</param>
        /// <param name="trayModel">映射类型</param>
        public static void TrayGatherParameterMap(short storehouse, Seat seat)
        {
            switch (storehouse)
            {
                case 1:
                    TrayMap.X01 = seat;
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayMap", "X01", ((int)seat).ToString());
                    break;
                case 2:
                    TrayMap.X03 = seat;
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayMap", "X03", ((int)seat).ToString());
                    break;
                case 3:
                    TrayMap.X05 = seat;
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayMap", "X05", ((int)seat).ToString());
                    break;
                case 4:
                    TrayMap.X08 = seat;
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayMap", "X08", ((int)seat).ToString());
                    break;
                case 5:
                    TrayMap.X13 = seat;
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayMap", "X13", ((int)seat).ToString());
                    break;
                case 6:
                    TrayMap.X15 = seat;
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayMap", "X15", ((int)seat).ToString());
                    break;
                case 7:
                    TrayMap.X176 = seat;
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayMap", "X176", ((int)seat).ToString());
                    break;
                case 8:
                    TrayMap.X177 = seat;
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayMap", "X177", ((int)seat).ToString());
                    break;
                case 9:
                    TrayMap.X178 = seat;
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayMap", "X178", ((int)seat).ToString());
                    break;
                case 10:
                    TrayMap.X19 = seat;
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayMap", "X19", ((int)seat).ToString());
                    break;
                default:
                    break;
            }
        }
        #endregion

        #region X13流向包装区单边使能
        public static class PackagingOrientation
        {
            public static void PackagingOrientationInit()
            {
                X13Unilateral = true;
            }
            /// <summary>
            /// X13单边流向
            /// </summary>
            public static bool X13Unilateral = false;
        }
        #endregion

        #region Tray流向包装区的分类
        public static void OrientationGotoPackagingParameterLoad()
        {
            try
            {
                TrayOrientationGotoPackaging.X01 = Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X01"));
                TrayOrientationGotoPackaging.X03 = Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X03"));
                TrayOrientationGotoPackaging.X05 = Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X05"));
                TrayOrientationGotoPackaging.X08 = Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X08"));
                TrayOrientationGotoPackaging.X13 = Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X13"));
                TrayOrientationGotoPackaging.X15 = Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X15"));
                TrayOrientationGotoPackaging.X176 = Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X176"));
                TrayOrientationGotoPackaging.X177 = Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X177"));
                TrayOrientationGotoPackaging.X178 = Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X178"));
                TrayOrientationGotoPackaging.X19 = Convert.ToInt16(XmlOperater.ReadItemFromXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X19"));
            }
            catch (Exception)
            {
            }

        }
        public static void OrientationGotoPackagingParameterSet(TrayModel trayModel, TrayOrientationGotoPackaging.Ori ori)
        {
            switch (trayModel)
            {
                case TrayModel.NULL:
                    break;
                case TrayModel.X01:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X01", ((int)ori).ToString());
                    break;
                case TrayModel.X03:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X03", ((int)ori).ToString());
                    break;
                case TrayModel.X05:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X05", ((int)ori).ToString());
                    break;
                case TrayModel.X08:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X08", ((int)ori).ToString());
                    break;
                case TrayModel.X13:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X13", ((int)ori).ToString());
                    break;
                case TrayModel.X15:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X15", ((int)ori).ToString());
                    break;
                case TrayModel.X176:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X176", ((int)ori).ToString());
                    break;
                case TrayModel.X177:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X177", ((int)ori).ToString());
                    break;
                case TrayModel.X178:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X178", ((int)ori).ToString());
                    break;
                case TrayModel.X19:
                    XmlOperater.WriteItemToXml(parameterFeilName, "IPC", "TrayOrientationGotoPackaging", "X19", ((int)ori).ToString());
                    break;
                case TrayModel.Unknown:
                    break;
                default:
                    break;
            }
        }
        #endregion
    }
}
